package com.hu.chat.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hu.chat.mapper.FriendMapper;
import com.hu.chat.mapper.UserMapper;
import com.hu.chat.model.base.Friend;
import com.hu.chat.model.base.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class FriendService extends ServiceImpl<FriendMapper, Friend> {

    @Resource
    UserMapper userMapper;
    @Resource
    WebSocketService webSocketService;

    // 好友上线提示
    public void online(Integer id) {
        User one = userMapper.selectById(id);

        baseMapper.selectList(new LambdaQueryWrapper<Friend>().eq(Friend::getFriendId, one.getId()))
                .stream()
                .map(Friend::getUserId)
                .forEach(useId -> webSocketService.systemMessage(useId, String.format("您的好友%s已经上线", one.getName())));
    }


}


